/***********************************************
/gen auto by zuitools
***********************************************/
#include "wifisettingActivity.h"

/*TAG:GlobalVariable全局变量*/
static ZKEditText* mEditTextPassPtr;
static ZKButton* mButtonconnectPtr;
static ZKTextView* mTextSecTypePtr;
static ZKTextView* mTextSSIDPtr;
static ZKTextView* mText3Ptr;
static ZKTextView* mText2Ptr;
static ZKTextView* mText1Ptr;
static ZKWindow* mwindow_setPtr;
static ZKTextView* mText_onoffPtr;
static ZKTextView* mLabel_1Ptr;
static ZKButton* mSYS_BACKPtr;
static ZKButton* mButton_swPtr;
static ZKWindow* mView_2Ptr;
static ZKListView* mListView_1Ptr;
static ZKWindow* mView_1Ptr;

/*register activity*/
REGISTER_ACTIVITY(wifisettingActivity);

typedef struct {
	int id; // 定时器ID ， 不能重复
	int time; // 定时器  时间间隔  单位 毫秒
}S_ACTIVITY_TIMEER;

#include "logic/wifisettingLogic.cc"

/***********/
typedef struct {
    int id;
    const char *pApp;
} SAppInfo;

/**
 *点击跳转window
 */
static SAppInfo sAppInfoTab[] = {
//  { ID_MAIN_TEXT, "TextViewActivity" },
};

/***************/
typedef bool (*ButtonCallback)(ZKButton *pButton);
/**
 * button onclick表
 */
typedef struct {
    int id;
    ButtonCallback callback;
}S_ButtonCallback;

/*TAG:ButtonCallbackTab按键映射表*/
static S_ButtonCallback sButtonCallbackTab[] = {
    ID_WIFISETTING_Buttonconnect, onButtonClick_Buttonconnect,
    ID_WIFISETTING_SYS_BACK, onButtonClick_SYS_BACK,
    ID_WIFISETTING_Button_sw, onButtonClick_Button_sw,
};
/***************/


typedef void (*SeekBarCallback)(ZKSeekBar *pSeekBar, int progress);
typedef struct {
    int id;
    SeekBarCallback callback;
}S_ZKSeekBarCallback;
/*TAG:SeekBarCallbackTab*/
static S_ZKSeekBarCallback SZKSeekBarCallbackTab[] = {
};


typedef int (*ListViewGetItemCountCallback)(const ZKListView *pListView);
typedef void (*ListViewobtainListItemDataCallback)(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index);
typedef void (*ListViewonItemClickCallback)(ZKListView *pListView, int index, int id);
typedef struct {
    int id;
    ListViewGetItemCountCallback getListItemCountCallback;
    ListViewobtainListItemDataCallback obtainListItemDataCallback;
    ListViewonItemClickCallback onItemClickCallback;
}S_ListViewFunctionsCallback;
/*TAG:ListViewFunctionsCallback*/
static S_ListViewFunctionsCallback SListViewFunctionsCallbackTab[] = {
    ID_WIFISETTING_ListView_1, getListItemCount_ListView_1, obtainListItemData_ListView_1, onListItemClick_ListView_1,
};


typedef void (*SlideWindowItemClickCallback)(ZKSlideWindow *pSlideWindow, int index);
typedef struct {
    int id;
    SlideWindowItemClickCallback onSlideItemClickCallback;
}S_SlideWindowItemClickCallback;
/*TAG:SlideWindowFunctionsCallbackTab*/
static S_SlideWindowItemClickCallback SSlideWindowItemClickCallbackTab[] = {
};


typedef void (*EditTextInputCallback)(const std::string &text);
typedef struct {
    int id;
    EditTextInputCallback onEditTextChangedCallback;
}S_EditTextInputCallback;
/*TAG:EditTextInputCallback*/
static S_EditTextInputCallback SEditTextInputCallbackTab[] = {
    ID_WIFISETTING_EditTextPass, onEditTextChanged_EditTextPass,
};

wifisettingActivity::wifisettingActivity() {
	//todo add init code here
}

wifisettingActivity::~wifisettingActivity() {
	//todo add init file here
    // 退出应用时需要反注册
    EASYUICONTEXT->unregisterGlobalTouchListener(this);
    onUI_quit();
    unregisterProtocolDataUpdateListener(onProtocolDataUpdate);
}

const char* wifisettingActivity::getAppName() const{
	return "wifisetting.ftu";
}

//TAG:onCreate
void wifisettingActivity::onCreate() {
	Activity::onCreate();
    mEditTextPassPtr = (ZKEditText*)findControlByID(ID_WIFISETTING_EditTextPass);if(mEditTextPassPtr!= NULL){mEditTextPassPtr->setTextChangeListener(this);}
    mButtonconnectPtr = (ZKButton*)findControlByID(ID_WIFISETTING_Buttonconnect);
    mTextSecTypePtr = (ZKTextView*)findControlByID(ID_WIFISETTING_TextSecType);
    mTextSSIDPtr = (ZKTextView*)findControlByID(ID_WIFISETTING_TextSSID);
    mText3Ptr = (ZKTextView*)findControlByID(ID_WIFISETTING_Text3);
    mText2Ptr = (ZKTextView*)findControlByID(ID_WIFISETTING_Text2);
    mText1Ptr = (ZKTextView*)findControlByID(ID_WIFISETTING_Text1);
    mwindow_setPtr = (ZKWindow*)findControlByID(ID_WIFISETTING_window_set);
    mText_onoffPtr = (ZKTextView*)findControlByID(ID_WIFISETTING_Text_onoff);
    mLabel_1Ptr = (ZKTextView*)findControlByID(ID_WIFISETTING_Label_1);
    mSYS_BACKPtr = (ZKButton*)findControlByID(ID_WIFISETTING_SYS_BACK);
    mButton_swPtr = (ZKButton*)findControlByID(ID_WIFISETTING_Button_sw);
    mView_2Ptr = (ZKWindow*)findControlByID(ID_WIFISETTING_View_2);
    mListView_1Ptr = (ZKListView*)findControlByID(ID_WIFISETTING_ListView_1);if(mListView_1Ptr!= NULL){mListView_1Ptr->setListAdapter(this);mListView_1Ptr->setItemClickListener(this);}
    mView_1Ptr = (ZKWindow*)findControlByID(ID_WIFISETTING_View_1);
	onUI_init();
        // 注册监听全局触摸
    EASYUICONTEXT->registerGlobalTouchListener(this);
    registerProtocolDataUpdateListener(onProtocolDataUpdate); 

    rigesterActivityTimer();
}

void wifisettingActivity::onClick(ZKBase *pBase) {
	//TODO: add widget onClik code 
    int buttonTablen = sizeof(sButtonCallbackTab) / sizeof(S_ButtonCallback);
    for (int i = 0; i < buttonTablen; ++i) {
        if (sButtonCallbackTab[i].id == pBase->getID()) {
            sButtonCallbackTab[i].callback((ZKButton*)pBase);
            break;
        }
    }


    int len = sizeof(sAppInfoTab) / sizeof(sAppInfoTab[0]);
    for (int i = 0; i < len; ++i) {
        if (sAppInfoTab[i].id == pBase->getID()) {
            EASYUICONTEXT->openActivity(sAppInfoTab[i].pApp);
            return;
        }
    }

	Activity::onClick(pBase);
}

void wifisettingActivity::onResume() {
	Activity::onResume();
}

void wifisettingActivity::onPause() {
	Activity::onPause();
}

void wifisettingActivity::onIntent(const Intent *intentPtr) {
	//TODO:  
	
	Activity::onIntent(intentPtr);
}

bool wifisettingActivity::onTimer(int id) {
	return onUI_Timer(id);
}

void wifisettingActivity::onProgressChanged(ZKSeekBar *pSeekBar, int progress){

    int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
    for (int i = 0; i < seekBarTablen; ++i) {
        if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
            SZKSeekBarCallbackTab[i].callback(pSeekBar, progress);
            break;
        }
    }
}

int wifisettingActivity::getListItemCount(const ZKListView *pListView) const{
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            return SListViewFunctionsCallbackTab[i].getListItemCountCallback(pListView);
            break;
        }
    }
    return 0;
}

void wifisettingActivity::obtainListItemData(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].obtainListItemDataCallback(pListView, pListItem, index);
            break;
        }
    }
}

void wifisettingActivity::onItemClick(ZKListView *pListView, int index, int id){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].onItemClickCallback(pListView, index, id);
            break;
        }
    }
}

void wifisettingActivity::onSlideItemClick(ZKSlideWindow *pSlideWindow, int index) {
    int tablen = sizeof(SSlideWindowItemClickCallbackTab) / sizeof(S_SlideWindowItemClickCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SSlideWindowItemClickCallbackTab[i].id == pSlideWindow->getID()) {
            SSlideWindowItemClickCallbackTab[i].onSlideItemClickCallback(pSlideWindow, index);
            break;
        }
    }
}

bool wifisettingActivity::onTouchEvent(const MotionEvent &ev) {
    return onwifisettingActivityTouchEvent(ev);
}

void wifisettingActivity::onTextChanged(ZKTextView *pTextView, const std::string &text) {
    int tablen = sizeof(SEditTextInputCallbackTab) / sizeof(S_EditTextInputCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SEditTextInputCallbackTab[i].id == pTextView->getID()) {
            SEditTextInputCallbackTab[i].onEditTextChangedCallback(text);
            break;
        }
    }
}

void wifisettingActivity::rigesterActivityTimer() {
    int tablen = sizeof(REGISTER_ACTIVITY_TIMER_TAB) / sizeof(S_ACTIVITY_TIMEER);
    for (int i = 0; i < tablen; ++i) {
        S_ACTIVITY_TIMEER temp = REGISTER_ACTIVITY_TIMER_TAB[i];
        registerTimer(temp.id, temp.time);
    }
}
